<?php
session_start();
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include "connectdb.php";
$username = $_SESSION['sess_Username'];
$password = $_SESSION['sess_Password'];

for ($i=0;$i<count($gender_array);$i++) {
$gender = $gender_array[$i];
}

//id
$ip = $_SERVER['REMOTE_ADDR'];
$today = Date("Y/m/d");
//$gender 

$user_type = $_POST["txtusertype"];
//echo $user_type;

$user_typeanother = $_POST["txttypeanother"];
//echo $user_typeanother;
if($user_type == "0" and $user_typeanother == ""){
		?>
		<script>
		alert("กรุณาระบุอาชีพของท่าน");
		history.back();
		</script>
		<?
}else{


$age_length = $_POST["agelength"];
switch ($age_length) {
   case 1 :
      $txtage = "ต่ำกว่า 15 ปี";
      break;
   case 2 :
      $txtage = "15 - 20 ปี";
      break;
   case 3 :
      $txtage = "20 - 25 ปี";
      break;
   case 4 :
      $txtage = "25 - 35 ปี";
      break;
   case 5 :
      $txtage = "35 ปีขึ้นไป";
	  break;
} 

$edulv = $_POST["edulv"];
switch ($edulv) {
   	case 1 :
      $txtedulv = "ประถมศึกษา";
      break;
   	case 2 :
      $txtedulv = "มัธยมศึกษา";
      break;
   	case 3 :
      $txtedulv = "ปวช.";
      break;
   	case 4 :
      $txtedulv = "ปวส.";
      break;
   	case 5 :
      $txtedulv = "ปริญญาตรี";
	  break;
	case 6 :
      $txtedulv = "ปริญญาโท";
	  break;
	case 7 :
      $txtedulv = "ปริญญาเอก";
	  break;
} 
//echo $txtedulv;


$SQL_SELECT_MAXUSER = "SELECT MAX(user_id)+1 FROM ag_user ;";
$resultmax = mysql_query($SQL_SELECT_MAXUSER);
$resultmax2 = mysql_result($resultmax,0);

if($resultmax2 == ""){$resultmax2 = 1;}


// id ip date gender age typeid //
$SQL_INSERT_USER = "INSERT INTO ag_user VALUES('$resultmax2','$ip','$today','$gender','$txtedulv','$txtage','$user_type','$user_typeanother');";
$result = mysql_db_query($dbname,$SQL_INSERT_USER)or die("ไม่สามารถลงทะเบียนได้");

		if($result){
			?>
			<script>
			alert("ลงทะเบียนเรียบร้อยแล้วคุณสามารถใช้บริการสื่อมัลติมีเดียได้ทันที")
			</script>
			<?
			
			$_SESSION["sess_user_register"] = session_id();	
			$_SESSION["sess_userid"] = $resultmax2;	
			
		}
		else 
		{
			?>
			<script>
			alert("ไม่สามารถลงทะเบียนได้")
			</script>
			<?
		}

}
?>
<meta http-equiv='refresh' content='0;URL=index.php'>
<!--<meta http-equiv='refresh' content='0;URL=admin_usertype.php'>-->